package com.songlanyun.modules.refillcard.controller.api;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.common.utils.Constant;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.user.controller.AbstractController;
import com.songlanyun.modules.user.exception.UserException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.songlanyun.modules.refillcard.entity.SaleRefillCardEntity;
import com.songlanyun.modules.refillcard.service.SaleRefillCardService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;


/**
 * 充值卡
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-12 10:30:59
 */
@RestController
@RequestMapping("api/refill/card")
public class SaleRefillCardApiController extends AbstractController {
    @Autowired
    private SaleRefillCardService saleRefillCardService;

    /**
     * 充值卡
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        List<SaleRefillCardEntity> list = saleRefillCardService.list(
                new LambdaQueryWrapper<SaleRefillCardEntity>()
                        .eq(SaleRefillCardEntity::getAdded, Constant.UP)//已上架的充值卡1
                        .orderByDesc(SaleRefillCardEntity::getCreateTime)
        );

        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        SaleRefillCardEntity saleRefillCard = saleRefillCardService.getById(id);

        return R.ok().put("data", saleRefillCard);
    }


}
